type(1)int
2025-02-04
Let’s take a look at the homework
import numpy as np
import os
def AP_check(folder):
AP_sweep_count = 0
for filename in os.listdir(folder):
if filename.endswith('.csv'):
with open(os.path.join(folder, filename), 'r') as file:
data = np.loadtxt(file, skiprows=1)
if any(data > 20):
AP_sweep_count += 1
print("AP found in " + filename)
else:
print('No AP in ' + filename)
return AP_sweep_count
file_path = 'data/sweeps_csv/'
sweep_count = AP_check(file_path)
print(sweep_count)is instead of ==.is and is not is also checking the type!The important question of what to do “if” something happens.
if something is True
somethingelse
something elsevalue = 3
1if value == 1:
print("the value is 1")
2elif value == 2:
print("the value is 2")
3elif value == 3:
4 print("the value is 3")
else:
print("the value is something else")value is 1
value is 2
value is 3
the value is 3
amplitude = 24
is_action_potential = "is AP" if amplitude > 0 else "no AP"
print(is_action_potential)is AP
everything_is_true = [True, True, True]
something_is_true = [True, False, False]
all(everything_is_true)
all(something_is_true)True
False
Given:
A = [3, 4, 5, 9, 12, 87, -65, 300, 450, -32]
Use for loops to:
1. Add 3 to each element of the list
2. Calculate the average of the list, but negative values are calculated as 0s
3. Find the maximum value
4. Find the index (position) of the max value
! range() and enumerate() - none of the two returns a list of objects!
while something is TrueThere are useful resources regarding errors